package com.atguigu.gulimall.search.controller;


import com.atguigu.common.to.es.SkuEsModel;
import com.atguigu.common.utils.R;
import com.atguigu.gulimall.search.service.ElasticSearchService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.List;

@RestController
@RequestMapping("/search")
@Slf4j
public class ElasticSearchController {

    @Autowired
    private ElasticSearchService elasticSearchService;

    @PostMapping("/save/product")
    public R spuStatusUp(@RequestBody List<SkuEsModel> skuEsModels) {
        boolean  b =false;
        try {
            b=elasticSearchService.spuStatusUp(skuEsModels);
        } catch (IOException e) {
            e.printStackTrace();
            return R.error();
        }
        if(!b){
            return R.ok();
        }else{
            return R.error();
        }

    }


}
